<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title></title>
    <script type="text/javascript" src="../applyandactivate/js/stats.js" charset="UTF-8"></script>
    <link rel="stylesheet" href="../applyandactivate/css/frozen.css">
    <link rel="stylesheet" href="../applyandactivate/css/style.css">
    <script src="../applyandactivate/lib/zepto.min.js"></script>
    <script src="../applyandactivate/js/frozen.js"></script>
    <script src="../js/link.js"></script>
    <script src="js/id.js"></script>

</head>

<body ontouchstart>
    <header class="ui-header ui-header-stable ui-border-b xc_header">
        <i class="ui-icon-return" onclick="history.back()"></i>
        <h1 class="ui-txt-feeds xc_header_h1">监护人信息</h1>
    </header>
    <section class="ui-container">
        <!--<h2 class="IDtit"></h2>-->
        <div id="form">
            <div class="ui-form">
                <form action="#" id="userInfo" name="userInfo">
                    <div class="ui-form-item xc_li_bottom">
                        <label for="username">
                            姓名<i class="ui-txt-red">*</i>
                        </label>
                        <input id="username" placeholder="请输入姓名" name="username" type="text" value="">
                        </a>
                    </div>
                    <div id="userMobile" style="display:none;" class="ui-form-item xc_li_bottom">
                        <label for="guardianMobile">
                            手机号<i class="ui-txt-red">*</i>
                        </label>
                        <input id="guardianMobile" placeholder="请输入手机号" name="guardianMobile" type="text" value="">
                        </a>
                    </div>
                    <div class="ui-form-item ui-border-b">
                        <label class="">
                            关系<i class="ui-txt-red">*</i>
                        </label>
                        <div class="ui-select xc_lttoption">
                            <select id="xc_relation">
                                <option selected value="1">父母</option>
                                <option value="2">祖父母</option>
                                <option value="3">外祖父母</option>
                                <option value="4">兄姐</option>
                                <option value="5">其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="ui-form-item ui-border-b">
                        <label class="">
                            证件类型<i class="ui-txt-red">*</i>
                        </label>
                        <div class="ui-select xc_option">
                            <select id="xc_idSelect">
                                <option selected value="CID">身份证</option>
                                <!--<option value="OTHER">军官证</option>
	                                <option value="OTHER">护照</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="ui-form-item ui-border-b">
                        <label>
                            证件号码<i class="ui-txt-red">*</i>
                        </label>
                        <input id="xc_idNum" type="text" placeholder="请输入证件号码" />
                    </div>
                </form>
            </div>
        </div>
    </section>
    <footer class="ui-footer">
        <button form="userInfo" class="xc_btn" type="button">确定</button>
    </footer>
</body>

</html>
<script>
//申请人年龄
function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if(r != null) {
            return unescape(r[2]);
        }
        return null;
    }
var userAge = getQueryString("userAge");//年龄
if (userAge<7) {
    $("#userMobile").css({"display":"block"});
}


// 身份验证
function authentication() {
    var pattern = /^([1-9]{1})([0-7]{1})(\d{13}$|\d{16}$|\d{15}(\d|X|x))$/;
    var IDNumber = $("#xc_idNum").val();
    console.log(IDNumber)
    if (pattern.test(IDNumber)) {
        console.log("正确");
    } else {
        alert("请填写正确的证件号码");
    }
}
$("#xc_idNum").blur(function() {
    if ($("#xc_idSelect").val() == "CID") {
        authentication();
    }
})
$(".xc_btn").click(function() {
    if ($("#username").val()!="") {
        if (!checkCard()) {
            return;
        } else {
            ajaxUserInfo();
        }
    }else{
        alert("请填写姓名");
    }
})
// 选择性别
function sexChecked(psidno) {
    var last = psidno[psidno.length - 2];
    if (last % 2 != 0) {
       return "男";
    } else {
        return "女";
    }
}
//手机号验证
$("#guardianMobile").blur(function(){
    var phone_pattern = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/;
    if (!phone_pattern.test($("#guardianMobile").val())) {
          alert("手机号填写错误");
    }
})
//缓存监护人参数
function ajaxUserInfo() {
    var guardianName = $("#username").val();
    var guardianRelation = $("#xc_relation").val();
    var guardianCardType = $("#xc_idSelect").val();
    var guardianCardNo = $("#xc_idNum").val();
    var guardianSex = sexChecked(guardianCardNo);
    var guardianMobile = $("#guardianMobile").val();
    // alert("姓名是："+username+"--关系："+xc_relation+"证件类型："+idCard+"证件号码："+idNo);
    var session = window.sessionStorage;
    session.setItem("guardianName",guardianName);//监护人姓名
    session.setItem("guardianSex",guardianSex);//监护人性别
    session.setItem("guardianRelation",guardianRelation);//监护人关系
    session.setItem("guardianCardType",guardianCardType);//监护人证件类型
    session.setItem("guardianCardNo",guardianCardNo);//监护人证件号
    session.setItem("guardianMobile",guardianMobile);//监护人手机号
    //平安开户
    if (userAge<7) {
        window.location.href="loading.html";//小于7岁直接跳转至护照申请
    }else{
        ajaxSuccess();
    }
}
//跳转到平安开户页面
function ajaxSuccess() {
    //sessionStorage中缓存的数据
    var channelCode = window.sessionStorage.getItem("channelCode") //渠道号
    var orderCode = window.sessionStorage.getItem("orderCode"); //订单号
    var businessCode = window.sessionStorage.getItem("businessCode"); //业务代码
    var realName = window.sessionStorage.getItem("name");
    var idNo = window.sessionStorage.getItem("cardNO");
    var dataStr = {
        channelCode: channelCode,
        orderCode: orderCode,
        businessCode: businessCode,
        realName:realName,
        // mobile:$("#phoneNum").val(),
        idNo: idNo,
        guardianName: $("#username").val(),
        guardianCardNo:$("#xc_idNum").val()
    }
    $.ajax({
        url: activatePath + '/pingan/toOpenAccount',
        type: 'post',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(dataStr),
        error: function() {}, //错误执行方法
        success: function(datas) {
                if (datas["success"]) {
                    console.log(datas.obj.openUrl);
                    location.href = datas.obj.openUrl;
                } else {
                    alert(datas["msg"]);
                }
            } //成功执行方法
    })
}

</script>
